home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / GDIMETA.PAK / COLORDLG.C < prev    next >
C/C++ Source or Header  |  1997-05-06  |  7KB  |  262 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993 - 1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE:    colordlg.c
  9. //
  10. //  PURPOSE:   Displays the "Color" dialog box
  11. //
  12. //  FUNCTIONS:
  13. //    CmdColor        - Displays the "Color" dialog box
  14. //    Color           - Processes messages for "Color" dialog box.
  15. //    MsgColorInit    - To initialize the color box with version info
  16. //                      from resources.
  17. //    MsgColorCommand - Process WM_COMMAND message sent to the color box.
  18. //    CmdColorOK      - Free the color box and related data. Do OK processing.
  19. //    CmdColorCancel  - Free the color box and related data. Do Cancel
  20. //                      processing.
  21. //    CmdColorPalCtrl - Handles notifications from the PalCtrl.
  22. //
  23. //  COMMENTS:
  24. //
  25. //
  26.  
  27. #include <windows.h>            // required for all Windows applications
  28. #include <windowsx.h>
  29. #include <commctrl.h>
  30. #include "globals.h"            // prototypes specific to this application
  31. #include "colordlg.h"
  32.  
  33. LRESULT MsgColorInit(HWND, UINT, WPARAM, LPARAM);
  34. LRESULT MsgColorCommand(HWND, UINT, WPARAM, LPARAM);
  35. LRESULT CmdColorOK(HWND, WORD, WORD, HWND);
  36. LRESULT CmdColorCancel(HWND, WORD, WORD, HWND);
  37. LRESULT CmdColorPalCtrl(HWND, WORD, WORD, HWND);
  38.  
  39. // Color dialog message table definition.
  40. MSD rgmsdColor[] =
  41. {
  42.     {WM_COMMAND,    MsgColorCommand},
  43.     {WM_INITDIALOG, MsgColorInit}
  44. };
  45.  
  46. MSDI msdiColor =
  47. {
  48.     sizeof(rgmsdColor) / sizeof(MSD),
  49.     rgmsdColor,
  50.     edwpNone
  51. };
  52.  
  53. // Color dialog command table definition.
  54. CMD rgcmdColor[] =
  55. {
  56.     {IDOK,        CmdColorOK},
  57.     {IDCANCEL,    CmdColorCancel},
  58.  
  59.     // PalCtrl notifications
  60.     {IDD_PALCTRL, CmdColorPalCtrl}
  61. };
  62.  
  63. CMDI cmdiColor =
  64. {
  65.     sizeof(rgcmdColor) / sizeof(CMD),
  66.     rgcmdColor,
  67.     edwpNone
  68. };
  69.  
  70. // Module specific "globals"  Used when a variable needs to be
  71. // accessed in more than on handler function.
  72.  
  73.  
  74. //
  75. //  FUNCTION: Color(HWND, UINT, WPARAM, LPARAM)
  76. //
  77. //  PURPOSE:  Processes messages for "Color" dialog box.
  78. //
  79. //  PARAMETERS:
  80. //    hdlg - window handle of the dialog box
  81. //    wMessage - type of message
  82. //    wparam - message-specific information
  83. //    lparam - message-specific information
  84. //
  85. //  RETURN VALUE:
  86. //    TRUE - message handled
  87. //    FALSE - message not handled
  88. //
  89. //  COMMENTS:
  90. //
  91. //     Display version information from the version section of the
  92. //     application resource.
  93. //
  94. //     Wait for user to click on "Ok" button, then close the dialog box.
  95. //
  96.  
  97. LRESULT CALLBACK Color(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
  98. {
  99.     return DispMessage(&msdiColor, hdlg, uMessage, wparam, lparam);
  100. }
  101.  
  102.  
  103. //
  104. //  FUNCTION: MsgColorInit(HWND, UINT, WPARAM, LPARAM)
  105. //
  106. //  PURPOSE: To initialize the Color box with version info from resources.
  107. //
  108. //  PARAMETERS:
  109. //    hwnd - The window handing the message.
  110. //    uMessage - The message number. (unused).
  111. //    wparam - Message specific data (unused).
  112. //    lparam - Message specific data (unused).
  113. //
  114. //  RETURN VALUE:
  115. //    Return FALSE (when calling SetFocus processing WM_INITDIALOG)
  116. //
  117. //  COMMENTS:
  118. //
  119.  
  120. #pragma argsused
  121. LRESULT MsgColorInit(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
  122. {
  123.     // Center the dialog over the application window
  124.     CenterWindow(hdlg, GetWindow(hdlg, GW_OWNER));
  125.  
  126.     // give the PalCtrl focus
  127.     SetFocus(GetDlgItem(hdlg, IDD_PALCTRL));
  128.  
  129.     // Set color selection in PalCtrl, LPARAM contains the desired index
  130.     SendDlgItemMessage(hdlg, IDD_PALCTRL, PCM_SETCURSEL, wparam, lparam);
  131.  
  132.     return FALSE;
  133. }
  134.  
  135. //
  136. //  FUNCTION: MsgColorCommand(HWND, UINT, WPARAM, LPARAM)
  137. //
  138. //  PURPOSE: Process WM_COMMAND message sent to the Color box.
  139. //
  140. //  PARAMETERS:
  141. //    hwnd - The window handing the message.
  142. //    uMessage - The message number. (unused).
  143. //    wparam - Message specific data (unused).
  144. //    lparam - Message specific data (unused).
  145. //
  146. //  RETURN VALUE:
  147. //    Always returns 0 - message handled.
  148. //
  149. //  COMMENTS:
  150. //    Uses this DipsCommand function defined in wndproc.c combined
  151. //    with the cmdiColor structure defined in this file to handle
  152. //    the command messages for the Color dialog box.
  153. //
  154.  
  155. #pragma argsused
  156. LRESULT MsgColorCommand(HWND   hwnd,
  157.                                 UINT   uMessage,
  158.                                 WPARAM wparam,
  159.                                 LPARAM lparam)
  160. {
  161.      return DispCommand(&cmdiColor, hwnd, wparam, lparam);
  162. }
  163.  
  164.  
  165. //
  166. //  FUNCTION: CmdColorOK(HWND, WORD, HWND)
  167. //
  168. //  PURPOSE: Free the Color box and related data.
  169. //
  170. //  PARAMETERS:
  171. //    hwnd - The window handling the command.
  172. //    wCommand - The command to be handled (unused).
  173. //    hwndCtrl - NULL (unused).
  174. //
  175. //  RETURN VALUE:
  176. //    Always returns TRUE.
  177. //
  178. //  COMMENTS:
  179. //    Calls EndDialog to finish the dialog session.
  180. //
  181.  
  182. #pragma argsused
  183. LRESULT CmdColorOK(HWND hdlg, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  184. {
  185.      // Get the current color selection
  186.      SendMessage(hwndCtrl, PCM_GETCURSEL, (WPARAM)NULL, (LPARAM)&palinfo);
  187.  
  188.      EndDialog(hdlg, TRUE);          // Exit the dialog
  189.     return TRUE;
  190. }
  191.  
  192.  
  193. //
  194. //  FUNCTION: CmdColorCancel(HWND, WORD, HWND)
  195. //
  196. //  PURPOSE: Free the Color box and related data.
  197. //
  198. //  PARAMETERS:
  199. //    hwnd - The window handling the command.
  200. //    wCommand - The command to be handled (unused).
  201. //    hwndCtrl - NULL (unused).
  202. //
  203. //  RETURN VALUE:
  204. //    Always returns TRUE.
  205. //
  206. //  COMMENTS:
  207. //    Calls EndDialog to finish the dialog session.
  208. //
  209.  
  210. #pragma argsused
  211. LRESULT CmdColorCancel(HWND hdlg, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  212. {
  213.      // user cancelled, return -1 in index field of palinfo
  214.      palinfo.index = -1;
  215.      palinfo.red = palinfo.green = palinfo.blue = 0;
  216.  
  217.     EndDialog(hdlg, TRUE);          // Exit the dialog
  218.     return TRUE;
  219. }
  220.  
  221.  
  222. //
  223. //  FUNCTION: CmdColorPalCtrl(HWND, WORD, HWND)
  224. //
  225. //  PURPOSE: Handles notifications from the PalCtrl.
  226. //
  227. //  PARAMETERS:
  228. //    hwnd - The window handling the command.
  229. //    wCommand - The command to be handled (unused).
  230. //    hwndCtrl - NULL (unused).
  231. //
  232. //  RETURN VALUE:
  233. //    Always returns TRUE.
  234. //
  235. //  COMMENTS:
  236. //
  237.  
  238. #pragma argsused
  239. LRESULT CmdColorPalCtrl(HWND hdlg, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  240. {
  241.      switch (wNotify)
  242.      {
  243.           case PCN_CHANGE:
  244.                 {
  245.                      // Get the current color selection
  246.                 SendMessage(hwndCtrl, PCM_GETCURSEL, (WPARAM)NULL, (LPARAM)&palinfo);
  247.  
  248.                 // Update index and RGB edit controls
  249.                 SetDlgItemInt(hdlg, IDD_INDEX, palinfo.index, FALSE);
  250.                 SetDlgItemInt(hdlg, IDD_RED, palinfo.red, FALSE);
  251.                 SetDlgItemInt(hdlg, IDD_GREEN, palinfo.green, FALSE);
  252.                 SetDlgItemInt(hdlg, IDD_BLUE, palinfo.blue, FALSE);
  253.             }
  254.             break;
  255.  
  256.         default:
  257.                 break;
  258.     }
  259.  
  260.     return TRUE;
  261. }
  262.